import { Component, OnInit } from '@angular/core';
// import {FormsModule} from "@angular/forms";
import { DataService } from '../../services/data.service';
@Component({
  selector: 'app-user',
  templateUrl: './user.component.html',
  styleUrls: ['./user.component.css']
})
export class UserComponent implements OnInit {
  name:string;
  age:number;
  email:string;
  editState:boolean=false;
  address:{
    street:string,
    city:string,
    state:string,
  }
  //也可按下面方法写
  // address:Address;
  hello:any;
  users:string[];
  constructor(public dataService:DataService) {
    console.log("1111");
    // this.users=this.dataService.getUsers();//
   
   }

  ngOnInit() {
    console.log("222");

    this.name="yeyongming";
    this.age=28;
    this.email="test@test.com";
    // this.address.city="广州";
    // this.address.state="天河区棠下";
    // this.address.street="广东省";
    this.address={
      city:"广州市",
      state:"广东省",
      street:"天河区棠下"
    }
    this.hello=["看书","写字","听歌"]
  }


  //按钮点击事件
  onClick(){
    console.log("测试点击事件");
    this.name="李福娣在睡大觉；叶永明在"
  }
  
  addHobby(hobby){
    console.log(hobby);
    this.hello.unshift(hobby);
    return false;
  }
  addHobby2(hobby){
    console.log(hobby);
    this.hello.unshift(hobby);
    return false;
  }
  deleteHobby(i){
    this.hello.splice(i,1);

  }
  isEdit(){
    this.editState = !this.editState;
  }
}

//定义接口
interface Address{
  street:string,
  city:string,
  state:string
}